package com.LachesismStorm.lachesism.member.controller;

import com.LachesismStorm.lachesism.core.common.response.ResponseResult;
import com.LachesismStorm.lachesism.member.dto.UmsMemberParam;
import com.LachesismStorm.lachesism.member.service.UmsMemberService;
import com.LachesismStorm.lachesism.member.vo.UmsMember;
import com.LachesismStorm.lachesism.member.vo.dto.WeChatParam;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Api(tags = "用户登录注册管理")
@RequestMapping("/member")
public class UmsMemberController {

    @Resource
    private UmsMemberService memberService;
    @ApiOperation(value = "openId登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "openId", value = "openId")
    })
    @PostMapping("/loginByOpenId")
    public ResponseResult loginByOpenId(@RequestParam String openId) {
        String token = memberService.loginByOpenId(openId);
        return ResponseResult.success(token, "登录成功");
    }


    @ApiOperation(value = "用户手机号注册登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "UmsMember", value = "用户注册信息")
    })
    @PostMapping("/register")
    public ResponseResult register(@RequestBody UmsMember member) {
        String token = memberService.register(member);
        return ResponseResult.success(token, "登录成功");
    }

    @ApiOperation(value = "获取用户信息")
    @PostMapping("/getUserInfo")
    public ResponseResult getUserInfo() {
        UmsMember umsMember = memberService.getUserInfo();
        return ResponseResult.success(umsMember, "查找成功");
    }

    @ApiOperation(value = "更新用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "UmsMemberParam", value = "用户手机号")
    })
    @PostMapping("/updateMemberInfo")
    public ResponseResult updateMemberInfo(@RequestBody UmsMember umsMember) {
        memberService.updateMemberInfo(umsMember);
        return ResponseResult.success(null, "更新成功");
    }

    @ApiOperation(value = "通过code获取手机号信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "WeChatParam", value = "code")
    })
    @PostMapping("/getWeChatInfoByCode")
    public ResponseResult updateMemberInfo(@RequestBody WeChatParam param) {
        WeChatParam weChatParam =  memberService.getWeChatInfoByCode(param);
        return ResponseResult.success(weChatParam, "查找成功");
    }
    @ApiOperation(value = "登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "WeChatParam", value = "code")
    })
    @PostMapping("/loginWithPhoneInfo")
    public ResponseResult loginWithPhoneInfo(@RequestBody WeChatParam param) {
        String token =  memberService.loginWithPhoneInfo(param);
        return ResponseResult.success(token, "登陆成功");
    }



}
